//
//  BIZConsultAnsCell.m
//  biz
//
//  Created by 边文辉 on 2017/3/22.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZConsultAnsCell.h"
#import "BIZConsultAModel.h"

@interface BIZConsultAnsCell ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topHeight;
@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *askHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *c2askCon;
@property (weak, nonatomic) IBOutlet UIButton *askBtn;

@end


@implementation BIZConsultAnsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setTopText:(NSString *)topText
{
    _topText = [topText copy];
    _topLabel.text = _topText;
}

- (void)setHiddenTop:(BOOL)hiddenTop
{
    _hiddenTop = hiddenTop;
    if (_hiddenTop) {
        _topHeight.constant = 0.f;
        _topLabel.text = @"";
    } else {
        _topHeight.constant = 10.f;
    }
}

- (void)setShowBottom:(BOOL)showBottom
{
    _showBottom = showBottom;
    if (_showBottom) {
        _askHeight.constant = 30.f;
        _c2askCon.constant = 10.f;
        _askBtn.hidden = NO;
        
    } else {
        _askHeight.constant = 0.f;
        _c2askCon.constant = 0.f;
        _askBtn.hidden = YES;
    }
}


- (void)setIndex:(NSInteger)index
{
    _index = index;
    if (_index == 1) {
        self.hiddenTop = YES;
        self.topText = @"";
    } else {
        self.hiddenTop = NO;
        self.topText = (_index % 2) ? @"咨询师回答:" : @"用户追问:";
    }
    
    if (_model) {
        [self setupContext];
    }
}

- (void)setModel:(BIZConsultAModel *)model
{
    _model = model;
    _contentLabel.text = _model.content;
    if (_index) {
        [self setupContext];
    }
    
}

- (void)setupContext
{
    self.showBottom = (_model.stage != 7) && (_index % 2) && (_index == _model.stage);
    
    switch (_index) {
        case 1:
            _contentLabel.text = _model.content;
            break;
        case 2:
            _contentLabel.text = _model.firstAsked;
            break;
        case 3:
            _contentLabel.text = _model.firstAnswer;
            break;
        case 4:
            _contentLabel.text = _model.secondAsked;
            break;
        case 5:
            _contentLabel.text = _model.secondAnswer;
            break;
        case 6:
            _contentLabel.text = _model.thirdAasked;
            break;
        case 7:
            _contentLabel.text = _model.thirdAnswer;
            break;
        default:
            break;
    }
    
    
}

- (IBAction)askBtnClicked:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(BIZConsultAnsCellAskBtnDidClicked:)]) {
        [self.delegate BIZConsultAnsCellAskBtnDidClicked:self];
    }
}

@end
